package com.bt.dmdb.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import com.bt.dmdb.dao.ProjectDao;
import com.bt.dmdb.model.Project;

@Repository("projectDao")
public class ProjectDaoImpl implements ProjectDao {

    @Autowired
    @Qualifier("sfDmdb")
    private SessionFactory sf;

    public Project getProject(long id) {
        return (Project) cs().get(Project.class, id);
    }

    public SessionFactory getSf() {
        return sf;
    }

    public void setSf(SessionFactory sf) {
        this.sf = sf;
    }

    private Session cs() {
        return sf.getCurrentSession();
    }

    @Override
    public long create(Project project) {
        cs().save(project);
        return (Long) cs().save(project);
    }
}
